package com.nulldev.util.networking.rudp;

public enum NetworkSendType {
	// If something went wrong use this
	ERROR(-1),

	// Notification that the reliable packed was sent correctly
	ACK(0),

	// Send an integer where in the queue the client is
	QUENUMBER(1),

	// Send an init signal to establish an connection
	INITSIGNAL(2),

	// Send reliable data between server and client
	RELIABLE_DATA(20),

	// Send unreliable data between server and client
	UNRELIABLE_DATA(21),

	// Send data about peers
	PEER_DATA(22),

	// Send a split reliable message, all parts will be delivered
	RELIABLE_SPLIT_DATA(30),

	// Send a split unreliable message, if any part of the message are lost all of
	// the message will be discarded
	// If the packages are getting in the wrong order the message will be discarded
	UNRELIABLE_SPLIT_DATA(31),

	PEER_SPLIT_DATA(32),

	/**
	 * Uses rUDP: Enhanced. Part of rUDP 1.1 and nullUtil 3.1
	 */
	UDP_E_PACKET(33),

	// If you just need to ping and tell you are alive, Or for testing
	PING(100);

	private int typeCode;

	private NetworkSendType(int tp) {
		typeCode = tp;
	}

	public int getTypeCode() {
		return typeCode;
	}

	public static NetworkSendType fromByteValue(byte type) {
		switch (type) {
			case 0:
				return ACK;
			case 1:
				return QUENUMBER;
			case 2:
				return INITSIGNAL;
			case 20:
				return RELIABLE_DATA;
			case 21:
				return UNRELIABLE_DATA;
			case 22:
				return PEER_DATA;
			case 30:
				return RELIABLE_SPLIT_DATA;
			case 31:
				return UNRELIABLE_SPLIT_DATA;
			case 32:
				return PEER_SPLIT_DATA;
			case 100:
				return PING;
			default:
				return ERROR;
		}
	}
}
